<?php
    //接收数据
    $user = array(
        'userId' => empty($_POST['userId']) ? 0 : $_POST['userId'],
        'username' => @$_POST['username'],
        'passkey' => @$_POST['passkey'],
        'grant' => @$_POST['grant'],
    );


require 'sql.php';//使用require语句包含并执行sql.php

//添加
if(isset($_POST["addmanagement"])) {
    $Msql = "insert into user (userId,username,passkey,`grant`) values('{$user['userId']}','{$user['username']}','{$user['passkey']}','{$user['grant']}')";
    $Mresult = mysql_query($Msql);
    if ($Mresult > 0) {
        echo "添加成功";
    } else {
        echo "添加失败";
    }
}
//删除
if(isset($_POST["delmanagement"])){
    $id = $_POST['userid'];
    $del="delete from user where userId=$id";
    $resultd= mysql_query($del);
    if($resultd != 0){
        echo  "删除成功";
    }else{
        echo  "删除失败";
    }
}

$add="select username,userId,passkey,`grant` from user where `grant`='admin'";//查询遍历
$aresult= mysql_query($add);
while($row=mysql_fetch_row($aresult)){
    $userl[]=$row;
}

?>